---
title: ""
output: pdf_document
geometry: "top=1in, bottom=1in, left=1in, right=1in"
header-includes:
    - \usepackage{caption}
    - \usepackage{lscape}
---

\newcommand{\blandscape}{\begin{landscape}}
\newcommand{\elandscape}{\end{landscape}}

\captionsetup[table]{labelformat=empty}

```{r setup, include=FALSE, message=FALSE}

# Setup
if (!require("pacman")) install.packages("pacman", repos = "http://cran.us.r-project.org"); library(pacman);
pacman::p_load(here, knitr, argparse, stringr, yaml, arrow, readr, dplyr, glue, magrittr, scales, kableExtra)

# Working directory and command line argument setup
current_script <- "generate_tables_and_figures/gen_benefit_cost_outputs/src/gen_benefit_cost_outputs.Rmd"
here::i_am(current_script)
source(here("R", "project_functions.R"))
task_dir <- here(dirname(dirname(file.path(current_script))))

knitr::opts_knit$set(root.dir = task_dir)
knitr::opts_chunk$set(include = TRUE, echo = FALSE, warning = FALSE, message = FALSE)
options(knitr.kable.NA = '', knitr.table.format = "latex", scipen = 999)

cl_args <- parse_make_args(c(
  "BCA_MODELS",
  "PAYROLL_STIPEND",
  "CONFIG_FILE",
  "OUT_DIR"
), inter_active = TRUE, task_dir = task_dir)

knitr_setup()
```

```{r}

source('R/benefit_cost_output_functions.R')

bca_results <- read_feather(cl_args$BCA_MODELS)
# transfer to participants
transfer_to_participants_tot <- read_csv(cl_args$PAYROLL_STIPEND) %>%
  filter(pathway == "all", period == "total") %>%
  pull(total_earnings)

config <- read_yaml(cl_args$CONFIG_FILE)

```

\begin{landscape}

```{r}
table <- print_bca_table(bca_results,
                         transfer_to_participants_tot,
                         config$less_inclusive_outcomes, config$more_inclusive_outcomes)

table

timestamp <- get_timestamp()
writeLines(table, glue(cl_args$OUT_DIR, "/outcomes_benefit_cost_{timestamp}.tex"))
writeLines(table, glue(cl_args$OUT_DIR, "/outcomes_benefit_cost_up_to_date.tex"))

```


\end{landscape}

